﻿using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using Teigha.Core;

namespace Teigha.TD
{
	public class OdDbField : OdDbObject
	{
		[EditorBrowsable(EditorBrowsableState.Never)]
		public OdDbField(IntPtr cPtr, bool cMemoryOwn) : base(TD_DbPINVOKE.OdDbField_SWIGUpcast(cPtr), cMemoryOwn)
		{
			this.swigCPtr = new HandleRef(this, cPtr);
		}

		[EditorBrowsable(EditorBrowsableState.Never)]
		public static HandleRef getCPtr(OdDbField obj)
		{
			if (obj != null)
			{
				return obj.swigCPtr;
			}
			return new HandleRef(null, IntPtr.Zero);
		}

		~OdDbField()
		{
			this.Dispose();
		}

		public override void Dispose()
		{
			if (this.swigCPtr.Handle != IntPtr.Zero)
			{
				if (this.swigCMemOwn)
				{
					lock (this.locker)
					{
						if (this.swigCPtr.Handle != IntPtr.Zero && this.swigCMemOwn)
						{
							this.swigCMemOwn = false;
							TD_DbPINVOKE.delete_OdDbField(this.swigCPtr);
						}
					}
					this.swigCMemOwn = false;
				}
				this.swigCPtr = new HandleRef(null, IntPtr.Zero);
			}
			GC.SuppressFinalize(this);
			base.Dispose();
		}

		public new static OdDbField cast(OdRxObject pObj)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbField_cast(OdRxObject.getCPtr(pObj));
			OdDbField result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdDbField)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdDbField)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdDbField)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new static OdRxClass desc()
		{
			OdRxClass result = (OdRxClass)Teigha.Core.Helpers.odrxCreateObjectInternal(TD_DbPINVOKE.OdDbField_desc(), false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new virtual OdRxClass isA()
		{
			OdRxClass result = (OdRxClass)Teigha.Core.Helpers.odrxCreateObjectInternal(TD_DbPINVOKE.OdDbField_isA(this.swigCPtr), false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new virtual OdRxObject queryX(OdRxClass protocolClass)
		{
			OdRxObject result = Teigha.Core.Helpers.odrxCreateObjectInternal(TD_DbPINVOKE.OdDbField_queryX(this.swigCPtr, OdRxClass.getCPtr(protocolClass)), false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new static OdDbField createObject()
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbField_createObject();
			OdDbField result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdDbField)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdDbField)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdDbField)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdResult setInObject(OdDbObject pOwner, string propertyName)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbField_setInObject(this.swigCPtr, OdDbObject.getCPtr(pOwner), propertyName);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdResult postInDatabase(OdDbDatabase pDb)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbField_postInDatabase(this.swigCPtr, OdDbDatabase.getCPtr(pDb));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdDbField.State state()
		{
			OdDbField.State result = (OdDbField.State)TD_DbPINVOKE.OdDbField_state(this.swigCPtr);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdDbField.EvalStatus evaluationStatus()
		{
			OdDbField.EvalStatus result = (OdDbField.EvalStatus)TD_DbPINVOKE.OdDbField_evaluationStatus(this.swigCPtr);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdDbField.EvalOption evaluationOption()
		{
			OdDbField.EvalOption result = (OdDbField.EvalOption)TD_DbPINVOKE.OdDbField_evaluationOption(this.swigCPtr);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdResult setEvaluationOption(OdDbField.EvalOption evaluationOption)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbField_setEvaluationOption(this.swigCPtr, (int)evaluationOption);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdDbField.FilingOption filingOption()
		{
			OdDbField.FilingOption result = (OdDbField.FilingOption)TD_DbPINVOKE.OdDbField_filingOption(this.swigCPtr);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdResult setFilingOption(OdDbField.FilingOption filingOption)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbField_setFilingOption(this.swigCPtr, (int)filingOption);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public string evaluatorId()
		{
			string result = TD_DbPINVOKE.OdDbField_evaluatorId(this.swigCPtr);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdResult setEvaluatorId(string evaluatorId)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbField_setEvaluatorId(this.swigCPtr, evaluatorId);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public bool isTextField()
		{
			bool result = TD_DbPINVOKE.OdDbField_isTextField(this.swigCPtr);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public string getFieldCode(OdDbField.FieldCodeFlag flags)
		{
			string result = TD_DbPINVOKE.OdDbField_getFieldCode(this.swigCPtr, (int)flags);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdResult setFieldCode(string fieldCode, OdDbField.FieldCodeFlag flags, OdDbFieldArray pChildFields)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbField_setFieldCode__SWIG_0(this.swigCPtr, fieldCode, (int)flags, OdDbFieldArray.getCPtr(pChildFields));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdResult setFieldCode(string fieldCode, OdDbField.FieldCodeFlag flags)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbField_setFieldCode__SWIG_1(this.swigCPtr, fieldCode, (int)flags);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdResult setFieldCode(string fieldCode)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbField_setFieldCode__SWIG_2(this.swigCPtr, fieldCode);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public uint childCount()
		{
			uint result = TD_DbPINVOKE.OdDbField_childCount(this.swigCPtr);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdDbField getChild(uint childIndex, OpenMode openMode)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbField_getChild(this.swigCPtr, childIndex, (int)openMode);
			OdDbField result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdDbField)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdDbField)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdDbField)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public string getFormat()
		{
			string result = TD_DbPINVOKE.OdDbField_getFormat(this.swigCPtr);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdResult setFormat(string format)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbField_setFormat(this.swigCPtr, format);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdResult evaluate(int nContext, OdDbDatabase pDb, out int pNumFound, out int pNumEvaluated)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbField_evaluate__SWIG_0(this.swigCPtr, nContext, OdDbDatabase.getCPtr(pDb), out pNumFound, out pNumEvaluated);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdResult evaluate(int nContext, OdDbDatabase pDb, out int pNumFound)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbField_evaluate__SWIG_1(this.swigCPtr, nContext, OdDbDatabase.getCPtr(pDb), out pNumFound);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdResult evaluate(int nContext, OdDbDatabase pDb)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbField_evaluate__SWIG_2(this.swigCPtr, nContext, OdDbDatabase.getCPtr(pDb));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdResult evaluate(int nContext)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbField_evaluate__SWIG_3(this.swigCPtr, nContext);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdValue.DataType dataType()
		{
			OdValue.DataType result = (OdValue.DataType)TD_DbPINVOKE.OdDbField_dataType(this.swigCPtr);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public string getValue()
		{
			string result = TD_DbPINVOKE.OdDbField_getValue__SWIG_0(this.swigCPtr);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdResult getValue(OdFieldValue pValue)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbField_getValue__SWIG_1(this.swigCPtr, OdFieldValue.getCPtr(pValue));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public bool hasHyperlink()
		{
			bool result = TD_DbPINVOKE.OdDbField_hasHyperlink(this.swigCPtr);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdResult getHyperlink(ref string psName, ref string psDescription, ref string psSubLocation, ref string psDisplayString)
		{
			IntPtr intPtr = Marshal.StringToCoTaskMemUni(psName);
			IntPtr value = intPtr;
			IntPtr intPtr2 = Marshal.StringToCoTaskMemUni(psDescription);
			IntPtr value2 = intPtr2;
			IntPtr intPtr3 = Marshal.StringToCoTaskMemUni(psSubLocation);
			IntPtr value3 = intPtr3;
			IntPtr intPtr4 = Marshal.StringToCoTaskMemUni(psDisplayString);
			IntPtr value4 = intPtr4;
			OdResult result;
			try
			{
				OdResult odResult = (OdResult)TD_DbPINVOKE.OdDbField_getHyperlink(this.swigCPtr, ref intPtr, ref intPtr2, ref intPtr3, ref intPtr4);
				if (TD_DbPINVOKE.SWIGPendingException.Pending)
				{
					throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
				}
				result = odResult;
			}
			finally
			{
				if (intPtr != value)
				{
					psName = Marshal.PtrToStringUni(intPtr);
				}
				if (intPtr2 != value2)
				{
					psDescription = Marshal.PtrToStringUni(intPtr2);
				}
				if (intPtr3 != value3)
				{
					psSubLocation = Marshal.PtrToStringUni(intPtr3);
				}
				if (intPtr4 != value4)
				{
					psDisplayString = Marshal.PtrToStringUni(intPtr4);
				}
			}
			return result;
		}

		public OdResult setHyperlink(string psName, string psDescription, string psSubLocation)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbField_setHyperlink__SWIG_0(this.swigCPtr, psName, psDescription, psSubLocation);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdResult setHyperlink(string psName, string psDescription)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbField_setHyperlink__SWIG_1(this.swigCPtr, psName, psDescription);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdResult removeHyperlink()
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbField_removeHyperlink(this.swigCPtr);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdFieldValue getData(string key)
		{
			OdFieldValue result = new OdFieldValue(TD_DbPINVOKE.OdDbField_getData(this.swigCPtr, key), true);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdResult setData(string key, OdFieldValue pData)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbField_setData(this.swigCPtr, key, OdFieldValue.getCPtr(pData));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new virtual OdResult dwgInFields(OdDbDwgFiler pFiler)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbField_dwgInFields(this.swigCPtr, OdDbDwgFiler.getCPtr(pFiler));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new virtual void dwgOutFields(OdDbDwgFiler pFiler)
		{
			TD_DbPINVOKE.OdDbField_dwgOutFields(this.swigCPtr, OdDbDwgFiler.getCPtr(pFiler));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public new virtual OdResult dxfInFields(OdDbDxfFiler pFiler)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbField_dxfInFields(this.swigCPtr, OdDbDxfFiler.getCPtr(pFiler));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new virtual void dxfOutFields(OdDbDxfFiler pFiler)
		{
			TD_DbPINVOKE.OdDbField_dxfOutFields(this.swigCPtr, OdDbDxfFiler.getCPtr(pFiler));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public new virtual void subClose()
		{
			TD_DbPINVOKE.OdDbField_subClose(this.swigCPtr);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		private object locker = new object();

		private HandleRef swigCPtr;

		[Flags]
		public enum State
		{
			kInitialized = 1,
			kCompiled = 2,
			kModified = 4,
			kEvaluated = 8,
			kHasCache = 16,
			kHasFormattedString = 32
		}

		[Flags]
		public enum EvalOption
		{
			kDisable = 0,
			kOnOpen = 1,
			kOnSave = 2,
			kOnPlot = 4,
			kOnEtransmit = 8,
			kOnRegen = 16,
			kOnDemand = 32,
			kAutomatic = 63
		}

		[Flags]
		public enum EvalContext
		{
			kOpen = 1,
			kSave = 2,
			kPlot = 4,
			kEtransmit = 8,
			kRegen = 16,
			kDemand = 32,
			kPreview = 64
		}

		[Flags]
		public enum EvalStatus
		{
			kNotYetEvaluated = 1,
			kSuccess = 2,
			kEvaluatorNotFound = 4,
			kSyntaxError = 8,
			kInvalidCode = 16,
			kInvalidContext = 32,
			kOtherError = 64
		}

		[Flags]
		public enum FieldCodeFlag
		{
			kRawCode = 0,
			kFieldCode = 1,
			kEvaluatedText = 2,
			kEvaluatedChildren = 4,
			kObjectReference = 8,
			kAddMarkers = 16,
			kEscapeBackslash = 32,
			kStripOptions = 64,
			kPreserveFields = 128,
			kTextField = 256,
			kPreserveOptions = 512,
			kDetachChildren = 1024,
			kChildObjectReference = 2048,
			kForExpression = 4096
		}

		public enum FilingOption
		{
			kSkipFilingResult = 1
		}
	}
}
